package j2025.j05;

import java.util.ArrayList;
import java.util.List;

/**
 * @Author 猫大仙
 */
public class j0513 {
    List<List<Integer>> rrr;
    List<Integer> tmp;
    int cou,t;
    public List<List<Integer>> combinationSum(int[] candidates, int target) {
        t = target;
        cou = 0;
        rrr = new ArrayList<>();
        tmp = new ArrayList<>();
        Dfs(candidates,0);
        return rrr;
    }
    public void Dfs(int[] candidates,int index){
        if(cou==t){
            rrr.add(new ArrayList<>(tmp));
            return;
        }else if(cou>t){
            return;
        }
        for (int i = index; i < candidates.length; i++) {

            cou += candidates[i];
            tmp.add(candidates[i]);
            Dfs(candidates,i);
            tmp.remove(tmp.size()-1);
            cou -= candidates[i];
        }
    }
}
